package cn.cwx.code.login.service;

import cn.cwx.code.common.utils.UserState;
import cn.cwx.code.home.dao.UserMapper;
import cn.cwx.code.home.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by GJ on 2017/6/21.
 */
@Service
public class LoginService {
    @Autowired
    UserMapper userMapper;
    /**
    *@Author  CWX
    *@Date 2017/6/21 18:15
    *@description 查询用户名
    */
    public boolean findUser(User user){
        String UserName=user.getUsername();
        User use=userMapper.selectByUserName(UserName);
        if(use!=null){
            return true;
        }
        return false;
    }
    /**
    *@Author  CWX
    *@Date 2017/6/21 19:43
    *@description 插入用户记录一条
     * 失败返回UserState.fail
     * 成功返回UserState.success
    */
    @Transactional
    public UserState login(User user) {
        Integer i=userMapper.insertUser(user);
        if(i!=null|i!=0){
           return UserState.success;
        }
        return UserState.fail;
    }
}
